package com.jfreer.mybatis.expand.model;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.JavaVisibility;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.codegen.AbstractJavaGenerator;
import org.mybatis.generator.codegen.mybatis3.model.BaseRecordGenerator;

import static org.mybatis.generator.internal.util.JavaBeansUtil.getSetterMethodName;

/**
 * Created by landy on 2017/11/30.
 */
public class FreeworkBaseRecordGenerator extends BaseRecordGenerator {
    public Method getJavaBeansSetter(IntrospectedColumn introspectedColumn) {
        return convertChainJavaBeansSetter(super.getJavaBeansSetter(introspectedColumn),introspectedColumn);

    }

    public static Method convertChainJavaBeansSetter(Method method, IntrospectedColumn introspectedColumn) {
        FullyQualifiedJavaType fqjt =new FullyQualifiedJavaType( introspectedColumn.getIntrospectedTable().getBaseRecordType());
        method.setReturnType(fqjt);

        StringBuilder sb = new StringBuilder();
        sb.append("return this;"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
        return method;
    }
}
